{extend name="base" /}
{block name="body"} 
<div class="layui-card">
    <table id="tableList" lay-filter="tableList"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-card-header">
        <div class="layui-btn-group">
       
            <a href="{:url('ArticleLog/deletelog')}" class="layui-btn layui-btn-danger ajax-delete layui-btn-sm" tiptext="确认删除文章一个月前的日志"><i class="layui-icon layui-icon-delete"></i> 删除一个月前日志</a> 
    {if(empty(ishone()))}  
        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>{:__('Multiple choice deletion')}</button>
        <button class="layui-btn layui-btn-sm" lay-event="refresh"><i class="layui-icon layui-icon-refresh-3"></i>{:__('Refresh')}</button>
        {/if}
        </div>
    </div>
</script>
    <!-- 表格操作列 -->
    <script type="text/html" id="tableTBTrack">
        <a href="{:url('ArticleLog/del')}?id={{d.id}}" class="layui-btn layui-btn-danger layui-btn-sm ajax-delete" tiptext="确认删除文章ID{{d.article_id}}"><i class="layui-icon layui-icon-delete"></i>{:__('delete')}</a>
    </script>
<script type="text/html" id="URL">
    <div><a href="{:getMyUrl()}{{ d.url }}" target="_blank">{{ d.url }}</a></div>
</script>
</div>
{/block}

{block name="js"}
<script>
    layui.use(['layer', 'form', 'table', 'util', 'dropdown'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;``
        var admin = layui.admin;
        var dropdown = layui.dropdown;
        // 渲染回访表格
        table.render({
            elem: '#tableList',
            toolbar: '#toolbarDemo',  //开启头部工具栏，并为其绑定左侧模板
            url: "{:url('articleLog/index_json')}",
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'] //自定义分页布局
                 //,curr: 5 //设定初始在第 5 页
            ,groups: 5 //只显示 1 个连续页码
            ,first: false //不显示首页
            ,last: false //不显示尾页
            ,prev: '<em>上一页</em>'
            ,next: '<em>下一页</em>'
            } ,
            cellMinWidth: 100,
            limit:'15',
            limits:['15','30','50','100','200','500'],
            size:'lg',even:true,
            cols: [[
                  {
                    type: 'checkbox'
                }, {
                    type:'numbers',
                    title:'#', 
                    width: 60
                }, {
                    field: 'name', 
                    title: '用户名', 
                    align: 'center', 
                    style:'background-color: #eee; color: #000;', 
                    width: 180,
                    templet: function(d){
                      return '<span style="color: #c00;">'+ d.name +'</span>'
                        }
                }, {
                    field: 'article_id', 
                    title: '文章ID', 
                    align: 'center', 
                    width: 100
                }, {
                    field: 'view', 
                    title: '浏览量', 
                    align: 'center', 
                    width: 80
                }, {
                    field: 'ip', 
                    title: 'IP地址', 
                    align: 'center', 
                    width: 140
                }, {
                    field: 'url', 
                    title: 'URL', 
                    align: 'center', 
                    width: 200, 
                    templet:'#URL'
                }, {
                    field: 'agent', 
                    title: '用户代理', 
                    align: 'center', 
                    width: 200
                }, {
                    field: 'create_time', 
                    title: '操作时间', 
                    align: 'center', 
                    width: 160
                }, {
                    align: 'center', 
                    toolbar: '#tableTBTrack', 
                    title: '操作', 
                    minWidth: 140
                }
            ]],
            parseData: function(res){ //res 即为原始返回的数据
                return {
                  "code": res.code, //解析接口状态
                  "msg": res.msg, //解析提示文本
                  "count": res.data.total, //解析数据长度
                  "data": res.data.data //解析数据列表
                };
            }
        });

    });
  //头工具栏事件
        table.on('toolbar(tableList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'delete':
             
                    var data = checkStatus.data;
                    var ids = [];
                    data.forEach(item => {
                        ids.push(item.id);
                    });
                    if (ids <= 0) {
                        return layer.msg('{:__('Please select a line')}', {icon: 0});
                    }
                layer.confirm('<i class="layui-icon layui-icon-help" style="font-size: 16px; color: #1E9FFF;"></i>确定删除?', function (index) {
                 var index = layer.msg('提交中，请稍候', {icon: 16,time: false,shade: 0.3});
                  $.post('/ArticleLog/del', {id: ids}, function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg, {icon: 1});
                            setTimeout(function () {
                                location.reload();  // 页面刷新
                            }, 1500)
                        } else {
                            layer.msg(res.msg, {icon: 0});
                        }
                    }, 'json');
                    });
                    break;
                case 'refresh':
                    location.reload();
                    break;
            }
        });
</script>
{/block}